home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / LIB211.ZIP;1 / WPMRGDEM.PRG < prev    next >
Encoding:
Text File  |  1993-12-15  |  4.9 KB  |  139 lines

  1. *-----------------------------------------------------------------------
  2. *-- Program...: WPMrgDem.prg
  3. *-- Programmer: Kenneth Chan (HazMatZak)  (CIS: 72662,1305)
  4. *-- Notes.....: Demo WP merge -- generate WP merge files directly 
  5. *--             from dBASE
  6. *-- Date......: 12/02/1993
  7. *-- More Expl.: There are two drivers, WPMERGE.PR2 and WPMERGEB.PR2, 
  8. *--             the only difference being that WPMERGEB has more 
  9. *--             aggressive bold support.  Both "B" and "U" STYLEs 
  10. *--             for ?/?? work -- the resulting WP text will be bolded 
  11. *--             and/or underlined.
  12. *-- 
  13. *--             The problem is that dBASE does not turn off bolding 
  14. *--             unless it knows the next expression is not bold.  If 
  15. *--             the last (or only) expression in a field is bold, the 
  16. *--             ending bold code ([bold] for the Reveal Codes-literate) 
  17. *--             does not appear until the beginning of the next field.  
  18. *--             This can cause rampant bolding in the resulting merged
  19. *--             document.
  20. *--
  21. *--             WPMERGEB "fixes" this by including [Bold][bold] codes 
  22. *--             at the end of every field.  When the generated file is 
  23. *--             converted by WordPerfect, it causes the bold to end at 
  24. *--             the end of the field, and eliminates the [bold] at the
  25. *--             beginning of the next field.  Unfortunately, if the 
  26. *--             last expression does not have a bold, there will be a 
  27. *--             [Bold][bold] at the end of the field. This has no ill 
  28. *--             effect, other than to uglify your WordPerfect document.
  29. *--             You can use a global search and replace to remove them, 
  30. *--             but....
  31. *--
  32. *--             If you're not generating a merge file with bold in it 
  33. *--             (and it's not clear why you'd want to do it in the 
  34. *--             first place), use the WPMERGE.PR2 driver instead; it 
  35. *--             does not have the extra bold codes.
  36. *-----------------------------------------------------------------------
  37.  
  38.    *-- Fake some data in a .DBF with an array
  39.    declare aDbf[ 3, 5 ]
  40.    aDbf[ 1, 1 ] = "Jane Doe"       && "record" 1
  41.    aDbf[ 1, 2 ] = "1234 Main St"
  42.    aDbf[ 1, 3 ] = "Anywhere"
  43.    aDbf[ 1, 4 ] = "US"
  44.    aDbf[ 1, 5 ] = "12345"
  45.    aDbf[ 2, 1 ] = "Ods Bodkins"    && "record" 2
  46.    aDbf[ 2, 2 ] = "987 W 654th St"
  47.    aDbf[ 2, 3 ] = "New York"
  48.    aDbf[ 2, 4 ] = "NY"
  49.    aDbf[ 2, 5 ] = "11011"        
  50.    aDbf[ 3, 1 ] = "Al Bendova"     && "record" 3
  51.    aDbf[ 3, 2 ] = "3300 Alameda"
  52.    aDbf[ 3, 3 ] = "Burbank"
  53.    aDbf[ 3, 4 ] = "CA"
  54.    aDbf[ 3, 5 ] = "91506"
  55.  
  56.    *-- Temporary changes to system memvars
  57.    private _pdriver, _padvance
  58.    *-- Use the WPMERGEB.PR2 printer driver because there's bolded text
  59.    _pdriver = "WPMERGEB.PR2"
  60.    *-- and advance by form feed for EJECT PAGE
  61.    _padvance = "FORMFEED"
  62.  
  63.    *-- Redirect printing to a file
  64.    cFile = "MAIL.LST"
  65.    set safety off
  66.    set printer to file ( cFile )
  67.    set safety on
  68.    set print on
  69.    set console off
  70.  
  71.    nRec = 1
  72.    do while nRec <= 3
  73.  
  74.       *-- First field always ?? AT 0
  75.       ?? aDbf[ nRec, 1 ] at 0               && Name
  76.  
  77.       *-- Subsequent fields print with ?
  78.       ? aDbf[ nRec, 2 ]                     && Address
  79.  
  80.       *-- Bold and underline styles work
  81.       *-- (at least in WP/DOS 5.1)          && City, State, Zip
  82.       ? aDbf[ nRec, 3 ], aDbf[ nRec, 4 ], aDbf[ nRec, 5 ] style "B"
  83.  
  84.       *-- End record with EJECT PAGE or ?? CHR( 12 ) but not EJECT
  85.       eject page
  86.  
  87.       nRec = nRec + 1
  88.    enddo
  89.  
  90.    set console on
  91.    set print off
  92.    *-- Close file
  93.    set printer to
  94.    *-- Remove EOF marker
  95.    do RemoveEOF with cFile
  96.    *-- Merge file with WPMRGDEM.WPD in WordPerfect
  97.  
  98. RETURN
  99.  
  100.  
  101.  
  102. PROCEDURE RemoveEOF
  103. *-----------------------------------------------------------------------
  104. *-- Programmer..: Kenneth Chan [Zak]  (CIS: 72662,1305)
  105. *-- Date........: 09/23/1993
  106. *-- Notes.......: Remove EOF marker from files
  107. *-- Written for.: dBASE IV, 1.5
  108. *-- Rev. History: 09/23/1993 1.0
  109. *-- Calls.......: <none>
  110. *-- Called by...: <any>
  111. *-- Usage.......: RemoveEOF with <cFile>
  112. *-- Example.....: do RemoveEOF with "PRINTOUT.TXT"
  113. *-- Returns.....: <na>
  114. *-- Parameters..: cFile      = name of file to truncate
  115. *-----------------------------------------------------------------------
  116.  
  117.    parameter cFile
  118.    *-- Make sure file exists
  119.    if file( cFile )
  120.       hFile = fopen( cFile, "RW" )
  121.       *-- If successful file open
  122.       if hFile > 0
  123.          *-- Goto last byte
  124.          nPtr = fseek( hFile, -1, 2 )
  125.          *-- If it's an EOF
  126.          if fread( hFile, 1 ) = chr( 26 )
  127.             *-- Reposition pointer
  128.             nPtr = fseek( hFile, -1, 2 )
  129.             *-- Truncate file
  130.             nPtr = fwrite( hFIle, "" )
  131.          endif
  132.          *-- Close file
  133.          nPtr = fclose( hFile )
  134.       endif
  135.     endif
  136.  
  137. RETURN
  138. *-- EoP: RemoveEoF
  139.